import 'dart:io';
import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_module_sale/common/plugin/bean/bean_ios_path_type.dart';
import 'package:dk_flutter_module_sale/common/plugin/plugin_common.dart';

///根据给定路径获取全路径 iOS自动拼接沙盒地址，Android返回原路径
Future<String> getRealPath(String path, {IosPathTypeBean type}) async {
  if (Platform.isIOS) {
    if (objEmpty(type)) {
      type = IosPathTypeBean.documents();
    }
    String prefix = await CommonPlugin().getIosPath(type: type);
    path = path.contains(prefix) ? path : prefix + path;
  }
  return Future.value(path);
}


class DKFileManager {
  factory DKFileManager() =>_getInstance();
  static DKFileManager get instance => _getInstance();
  static DKFileManager _instance;
  String documentPath;
  DKFileManager._internal() {
    CommonPlugin().getIosPath(type: IosPathTypeBean.documents()).then((String path){
      this.documentPath = path;
    });
  }
  static DKFileManager _getInstance() {
    if (_instance == null) {
      _instance = new DKFileManager._internal();
    }
    return _instance;
  }
}
